package com.cnooc.aicv.lmapp.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
@Data
public  class ComplexContent implements Content {
    @JsonProperty("value")
    private List<ComplexContentItem> content;

    @Data
    public static class ComplexContentItem {
        @JsonProperty("type")
        private String type;

        @JsonProperty("image_url")
        private ImageUrl imageUrl;

        @JsonProperty("text")
        private String text;

    }

    public void setInputBase64(String inputBase64){
        for(ComplexContentItem item : this.content){
            if(item.getImageUrl() != null && "image_url".equals(item.getType())){
                log.debug("old image length:{}",item.getImageUrl().getUrl().length());
                item.getImageUrl().setUrl(inputBase64);
                log.debug("new image length:{}",inputBase64.length());
            }
            continue;
        }
    }
    public void setInputPrompt(String inputPrompt){
        for(ComplexContentItem item : this.content){
            if( "text".equals(item.getType())){
                log.info("old prompt length:{}",item.getText().length());

                item.setText(inputPrompt);
                log.info("new prompt length:{}",inputPrompt.length());

            }
            continue;
        }

    }

}
